﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FR.SAFTAnalyser.Model;

namespace FR.SAFTAnalyser.SAFT
{
    internal class ConvertV1ToV3
    {
        internal static AuditFile Convert(Model.V1.AuditFile oldFileVersion)
        {
            if (oldFileVersion == null)
                return null;

            AuditFile auditFile = new AuditFile();

            auditFile.Header = GetHeader(oldFileVersion.Header);
            auditFile.MasterFiles = GetMastesFiles(oldFileVersion.MasterFiles);
            auditFile.GeneralLedgerEntries = GetGeneralLedgerEntries(oldFileVersion.GeneralLedgerEntries);
            auditFile.SourceDocuments = GetSourceDocuments(oldFileVersion.SourceDocuments);

            return auditFile;
        }

        #region SourceDocuments
        private static SourceDocuments GetSourceDocuments(Model.V1.SourceDocuments sourceDocumentsOld)
        {
            if (sourceDocumentsOld == null)
                return null;

            SourceDocuments sourceDocuments = new SourceDocuments();
            sourceDocuments.SalesInvoices = GetSalesInvoices(sourceDocumentsOld.SalesInvoices);

            return sourceDocuments;
        }

        private static SourceDocumentsSalesInvoices GetSalesInvoices(Model.V1.SourceDocumentsSalesInvoices sourceDocumentsSalesInvoicesOld)
        {
            if (sourceDocumentsSalesInvoicesOld == null)
                return null;

            SourceDocumentsSalesInvoices sourceDocumentsSalesInvoices = new SourceDocumentsSalesInvoices();
            sourceDocumentsSalesInvoices.NumberOfEntries = sourceDocumentsSalesInvoicesOld.NumberOfEntries;
            sourceDocumentsSalesInvoices.TotalCredit = sourceDocumentsSalesInvoicesOld.TotalCredit;
            sourceDocumentsSalesInvoices.TotalDebit = sourceDocumentsSalesInvoicesOld.TotalDebit;
            sourceDocumentsSalesInvoices.Invoice = GetInvoices(sourceDocumentsSalesInvoicesOld.Invoice);

            return sourceDocumentsSalesInvoices;
        }

        private static SourceDocumentsSalesInvoicesInvoice[] GetInvoices(Model.V1.SourceDocumentsSalesInvoicesInvoice[] invoicesOld)
        {
            if (invoicesOld == null)
                return null;

            List<SourceDocumentsSalesInvoicesInvoice> invoices = new List<SourceDocumentsSalesInvoicesInvoice>();

            foreach (var invoiceOld in invoicesOld)
            {
                SourceDocumentsSalesInvoicesInvoice invoice = new SourceDocumentsSalesInvoicesInvoice();
                invoice.CustomerID = invoiceOld.CustomerID;
                invoice.DocumentStatus = new SourceDocumentsSalesInvoicesInvoiceDocumentStatus();
                invoice.DocumentStatus.InvoiceStatus = EnumParser.Parse<InvoiceStatus>(invoiceOld.InvoiceStatus.ToString());
                invoice.DocumentTotals = GetInvoiceTotals(invoiceOld.DocumentTotals);
                invoice.Hash = invoiceOld.Hash;
                invoice.HashControl = invoiceOld.HashControl;
                invoice.InvoiceDate = invoiceOld.InvoiceDate;
                invoice.InvoiceNo = invoiceOld.InvoiceNo;
                invoice.InvoiceType = EnumParser.Parse<InvoiceType>(invoiceOld.InvoiceType.ToString());
                invoice.Line = GetInvoiceLines(invoiceOld.Line);
                invoice.Period = invoiceOld.Period;
                invoice.SpecialRegimes = new SpecialRegimes();
                invoice.SpecialRegimes.SelfBillingIndicator = invoiceOld.SelfBillingIndicator;
                invoice.ShipFrom = GetInvoiceShip(invoiceOld.ShipFrom);
                invoice.ShipTo = GetInvoiceShip(invoiceOld.ShipTo);
                invoice.SystemEntryDate = invoiceOld.SystemEntryDate;
                invoice.TransactionID = invoiceOld.TransactionID;

                invoices.Add(invoice);
            }

            return invoices.ToArray();
        }

        private static ShippingPointStructure GetInvoiceShip(Model.V1.ShippingPointStructure shipFromOld)
        {
            if (shipFromOld == null)
                return null;

            ShippingPointStructure shipFrom = new ShippingPointStructure();
            shipFrom.DeliveryDate = shipFromOld.DeliveryDate;
            shipFrom.DeliveryDateSpecified = shipFromOld.DeliveryDateSpecified;
            shipFrom.DeliveryID = new string[] { shipFromOld.DeliveryID };
            if (shipFromOld.Address != null)
            {
                shipFrom.Address = new AddressStructure();
                shipFrom.Address.AddressDetail = shipFromOld.Address.AddressDetail;
                shipFrom.Address.BuildingNumber = shipFromOld.Address.BuildingNumber;
                shipFrom.Address.City = shipFromOld.Address.City;
                shipFrom.Address.Country = shipFromOld.Address.Country;
                shipFrom.Address.PostalCode = shipFromOld.Address.PostalCode;
                shipFrom.Address.Region = shipFromOld.Address.Region;
                shipFrom.Address.StreetName = shipFromOld.Address.StreetName;
            }
            return shipFrom;
        }

        private static SourceDocumentsSalesInvoicesInvoiceLine[] GetInvoiceLines(Model.V1.SourceDocumentsSalesInvoicesInvoiceLine[] invoiceLinesOld)
        {
            if (invoiceLinesOld == null)
                return null;

            List<SourceDocumentsSalesInvoicesInvoiceLine> invoiceLines = new List<SourceDocumentsSalesInvoicesInvoiceLine>();

            foreach (var lineOld in invoiceLinesOld)
            {
                SourceDocumentsSalesInvoicesInvoiceLine line = new SourceDocumentsSalesInvoicesInvoiceLine();
                line.Description = lineOld.Description;
                line.Item = lineOld.Item;
                line.ItemElementName = EnumParser.Parse<ItemChoiceType5>(lineOld.ItemElementName.ToString());
                line.LineNumber = lineOld.LineNumber;
                line.OrderReferences = GetOrderReferences(lineOld.OrderReferences);
                line.ProductCode = lineOld.ProductCode;
                line.ProductDescription = lineOld.ProductDescription;
                line.Quantity = lineOld.Quantity;
                line.References = GetLineReferences(lineOld.References);
                line.SettlementAmount = lineOld.SettlementAmount;
                line.SettlementAmountSpecified = lineOld.SettlementAmountSpecified;
                line.Tax = GetLineTax(lineOld.Tax);
                line.TaxExemptionReason = lineOld.TaxExemptionReason;
                line.TaxPointDate = lineOld.TaxPointDate;
                line.UnitOfMeasure = lineOld.UnitOfMeasure;
                line.UnitPrice = lineOld.UnitPrice;

                invoiceLines.Add(line);
            }

            return invoiceLines.ToArray();
        }

        private static Tax GetLineTax(Model.V1.Tax taxOld)
        {
            if (taxOld == null)
                return null;

            Tax tax = new Tax();
            tax.Item = taxOld.Item;
            tax.ItemElementName = EnumParser.Parse<ItemChoiceType1>(taxOld.ItemElementName.ToString());
            tax.TaxCode = taxOld.TaxCode;
            tax.TaxCountryRegion = taxOld.TaxCountryRegion;
            tax.TaxType = EnumParser.Parse<TaxType>(taxOld.TaxType.ToString());

            return tax;
        }

        private static References[] GetLineReferences(Model.V1.References referencesOld)
        {
            if (referencesOld == null || referencesOld.CreditNote == null)
                return null;

            List<References> references = new List<References>();
            References reference = new References();
            reference.Reason = referencesOld.CreditNote.Reason;
            reference.Reference = referencesOld.CreditNote.Reference;

            return references.ToArray();
        }

        private static OrderReferences[] GetOrderReferences(Model.V1.OrderReferences[] orderReferencesOld)
        {
            if (orderReferencesOld == null)
                return null;

            List<OrderReferences> orderReferences = new List<OrderReferences>();

            foreach (var orderRefOld in orderReferencesOld)
            {
                OrderReferences orderRef = new OrderReferences();
                orderRef.OrderDate = orderRefOld.OrderDate;
                orderRef.OrderDateSpecified = orderRefOld.OrderDateSpecified;
                orderRef.OriginatingON = orderRefOld.OriginatingON;

                orderReferences.Add(orderRef);
            }

            return orderReferences.ToArray();
        }

        private static SourceDocumentsSalesInvoicesInvoiceDocumentTotals GetInvoiceTotals(Model.V1.SourceDocumentsSalesInvoicesInvoiceDocumentTotals documentTotalsOld)
        {
            if (documentTotalsOld == null)
                return null;

            SourceDocumentsSalesInvoicesInvoiceDocumentTotals documentTotals = new SourceDocumentsSalesInvoicesInvoiceDocumentTotals();
            if (documentTotalsOld.Currency != null)
            {
                documentTotals.Currency = new Currency();
                documentTotals.Currency.CurrencyCode = documentTotalsOld.Currency.CurrencyCode;
                documentTotals.Currency.CurrencyAmount = documentTotalsOld.Currency.Item;
            }
            documentTotals.GrossTotal = documentTotalsOld.GrossTotal;
            documentTotals.NetTotal = documentTotalsOld.NetTotal;
            if (documentTotalsOld.Settlement != null)
            {
                documentTotals.Settlement = new Settlement[]
                {
                    new Settlement
                    {
                        SettlementAmount = documentTotalsOld.Settlement.SettlementAmount,
                        SettlementAmountSpecified = documentTotalsOld.Settlement.SettlementAmountSpecified,
                        SettlementDate = documentTotalsOld.Settlement.SettlementDate,
                        SettlementDateSpecified = documentTotalsOld.Settlement.SettlementDateSpecified,
                        SettlementDiscount = documentTotalsOld.Settlement.SettlementDiscount
                    }
                };
            }
            documentTotals.TaxPayable = documentTotalsOld.TaxPayable;

            return documentTotals;
        } 
        #endregion

        #region GeneralLedger
        private static GeneralLedgerEntries GetGeneralLedgerEntries(Model.V1.GeneralLedgerEntries generalLedgerEntriesOld)
        {
            if (generalLedgerEntriesOld == null)
                return null;

            GeneralLedgerEntries generalLedgerEntries = new GeneralLedgerEntries();
            generalLedgerEntries.NumberOfEntries = generalLedgerEntriesOld.NumberOfEntries;
            generalLedgerEntries.TotalCredit = generalLedgerEntriesOld.TotalCredit;
            generalLedgerEntries.TotalDebit = generalLedgerEntriesOld.TotalDebit;
            generalLedgerEntries.Journal = GetJornal(generalLedgerEntriesOld.Journal);

            return generalLedgerEntries;
        }

        private static GeneralLedgerEntriesJournal[] GetJornal(Model.V1.GeneralLedgerEntriesJournal[] generalLedgerEntriesJournalOld)
        {
            if (generalLedgerEntriesJournalOld == null)
                return null;

            List<GeneralLedgerEntriesJournal> generalLedgerEntriesJournal = new List<GeneralLedgerEntriesJournal>();

            foreach (var entryJornalOld in generalLedgerEntriesJournalOld)
            {
                GeneralLedgerEntriesJournal entryJournal = new GeneralLedgerEntriesJournal();
                entryJournal.Description = entryJornalOld.Description;
                entryJournal.JournalID = entryJornalOld.JournalID;
                entryJournal.Transaction = GetTransaction(entryJornalOld.Transaction);

                generalLedgerEntriesJournal.Add(entryJournal);
            }

            return generalLedgerEntriesJournal.ToArray();
        }

        private static GeneralLedgerEntriesJournalTransaction[] GetTransaction(Model.V1.GeneralLedgerEntriesJournalTransaction[] generalLedgerEntriesJournalTransactionOld)
        {
            if (generalLedgerEntriesJournalTransactionOld == null)
                return null;

            List<GeneralLedgerEntriesJournalTransaction> generalLedgerEntriesJournalTransaction = new List<GeneralLedgerEntriesJournalTransaction>();

            foreach (var entryJornalTransactionOld in generalLedgerEntriesJournalTransactionOld)
            {
                GeneralLedgerEntriesJournalTransaction entryJornalTransaction = new GeneralLedgerEntriesJournalTransaction();
                entryJornalTransaction.Description = entryJornalTransactionOld.Description;
                entryJornalTransaction.DocArchivalNumber = entryJornalTransactionOld.DocArchivalNumber;
                entryJornalTransaction.GLPostingDate = entryJornalTransactionOld.GLPostingDate;
                entryJornalTransaction.Line = GetJornalTransactionLine(entryJornalTransactionOld.Line);
                entryJornalTransaction.Period = entryJornalTransactionOld.Period;
                entryJornalTransaction.SourceID = entryJornalTransactionOld.SourceID;
                entryJornalTransaction.TransactionDate = entryJornalTransactionOld.TransactionDate;
                entryJornalTransaction.TransactionID = entryJornalTransactionOld.TransactionID;
                entryJornalTransaction.TransactionType = EnumParser.Parse<TransactionType>(entryJornalTransactionOld.TransactionType.ToString());

                generalLedgerEntriesJournalTransaction.Add(entryJornalTransaction);
            }

            return generalLedgerEntriesJournalTransaction.ToArray();
        }

        private static GeneralLedgerEntriesJournalTransactionLine[] GetJornalTransactionLine(Model.V1.GeneralLedgerEntriesJournalTransactionLine[] entriesJournalTransactionLinesOld)
        {
            if (entriesJournalTransactionLinesOld == null)
                return null;

            List<GeneralLedgerEntriesJournalTransactionLine> entriesJournalTransactionLines = new List<GeneralLedgerEntriesJournalTransactionLine>();

            foreach (var entriesJournalTransactionLineOld in entriesJournalTransactionLinesOld)
            {
                GeneralLedgerEntriesJournalTransactionLine entriesJournalTransactionLine = new GeneralLedgerEntriesJournalTransactionLine();
                entriesJournalTransactionLine.AccountID = entriesJournalTransactionLineOld.AccountID;
                entriesJournalTransactionLine.Description = entriesJournalTransactionLineOld.Description;
                entriesJournalTransactionLine.Item = entriesJournalTransactionLineOld.Item;
                entriesJournalTransactionLine.ItemElementName = EnumParser.Parse<ItemChoiceType4>(entriesJournalTransactionLineOld.ItemElementName.ToString());
                entriesJournalTransactionLine.RecordID = entriesJournalTransactionLineOld.RecordID;
                entriesJournalTransactionLine.SourceDocumentID = entriesJournalTransactionLineOld.SourceDocumentID;
                entriesJournalTransactionLine.SystemEntryDate = entriesJournalTransactionLineOld.SystemEntryDate;


                entriesJournalTransactionLines.Add(entriesJournalTransactionLine);
            }

            return entriesJournalTransactionLines.ToArray();
        }
        #endregion

        #region Header
        static Header GetHeader(Model.V1.Header oldHeader)
        {
            if (oldHeader == null)
                return null;

            Header header = new Header();
            header.AuditFileVersion = oldHeader.AuditFileVersion;
            header.BusinessName = oldHeader.BusinessName;
            if (oldHeader.CompanyAddress != null)
            {
                header.CompanyAddress = new AddressStructurePT();
                header.CompanyAddress.AddressDetail = oldHeader.CompanyAddress.AddressDetail;
                header.CompanyAddress.BuildingNumber = oldHeader.CompanyAddress.BuildingNumber;
                header.CompanyAddress.City = oldHeader.CompanyAddress.City;
                header.CompanyAddress.Country = oldHeader.CompanyAddress.Country.ToString();
                header.CompanyAddress.PostalCode = oldHeader.CompanyAddress.PostalCode;
                header.CompanyAddress.Region = oldHeader.CompanyAddress.Region;
                header.CompanyAddress.StreetName = oldHeader.CompanyAddress.StreetName;
            }
            header.CompanyID = oldHeader.CompanyID;
            header.CompanyName = oldHeader.CompanyName;
            header.CurrencyCode = oldHeader.CurrencyCode;
            header.DateCreated = oldHeader.DateCreated;
            header.Email = oldHeader.Email;
            header.EndDate = oldHeader.EndDate;
            header.Fax = oldHeader.Fax;
            header.FiscalYear = oldHeader.FiscalYear;
            header.HeaderComment = oldHeader.HeaderComment;
            header.ProductCompanyTaxID = oldHeader.ProductCompanyTaxID;
            header.ProductID = oldHeader.ProductID;
            header.ProductVersion = oldHeader.ProductVersion;
            header.SoftwareCertificateNumber = oldHeader.SoftwareCertificateNumber;
            header.StartDate = oldHeader.StartDate;
            TaxAccountingBasis taxAccountingBasis;
            Enum.TryParse<TaxAccountingBasis>(oldHeader.TaxAccountingBasis.ToString(), true, out taxAccountingBasis);
            header.TaxAccountingBasis = taxAccountingBasis;
            header.TaxEntity = oldHeader.TaxEntity;
            header.TaxRegistrationNumber = oldHeader.TaxRegistrationNumber;
            header.Telephone = oldHeader.Telephone;
            header.Website = oldHeader.Website;

            return header;
        } 
        #endregion

        #region MasterFiles
        static AuditFileMasterFiles GetMastesFiles(object[] masterFilesOld)
        {
            if (masterFilesOld == null)
                return null;

            AuditFileMasterFiles masterFiles = new AuditFileMasterFiles();
            masterFiles.Customer = GetCustomers(masterFilesOld.OfType<Model.V1.Customer>());
            masterFiles.Product = GetProducts(masterFilesOld.OfType<Model.V1.Product>());
            masterFiles.TaxTable = GetTaxTable(masterFilesOld.OfType<Model.V1.TaxTable>());
            masterFiles.Supplier = GetSupplier(masterFilesOld.OfType<Model.V1.Supplier>());
            masterFiles.GeneralLedger = GetGeneralLedger(masterFilesOld.OfType<Model.V1.GeneralLedger>());

            return masterFiles;
        }

        private static GeneralLedger[] GetGeneralLedger(IEnumerable<Model.V1.GeneralLedger> generalLedgersOld)
        {
            if (generalLedgersOld == null)
                return null;

            List<GeneralLedger> generalLedgers = new List<GeneralLedger>();

            foreach (Model.V1.GeneralLedger generalLedgerOld in generalLedgersOld)
            {
                GeneralLedger generalLedger = new GeneralLedger();
                generalLedger.AccountDescription = generalLedgerOld.AccountDescription;
                generalLedger.AccountID = generalLedgerOld.AccountID;
                generalLedger.OpeningCreditBalance = generalLedgerOld.OpeningCreditBalance;
                generalLedger.OpeningDebitBalance = generalLedgerOld.OpeningDebitBalance;

                generalLedgers.Add(generalLedger);
            }

            return generalLedgers.ToArray();
        }

        private static Supplier[] GetSupplier(IEnumerable<Model.V1.Supplier> suppliersOld)
        {
            if (suppliersOld == null)
                return null;

            List<Supplier> suppliers = new List<Supplier>();

            foreach (Model.V1.Supplier supplierOld in suppliersOld)
            {
                Supplier supplier = new Supplier();
                supplier.AccountID = supplierOld.AccountID;
                if (supplierOld.BillingAddress != null)
                {
                    supplier.BillingAddress = new SupplierAddressStructure();
                    supplier.BillingAddress.AddressDetail = supplierOld.BillingAddress.AddressDetail;
                    supplier.BillingAddress.BuildingNumber = supplierOld.BillingAddress.BuildingNumber;
                    supplier.BillingAddress.City = supplierOld.BillingAddress.City;
                    supplier.BillingAddress.Country = supplierOld.BillingAddress.Country;
                    supplier.BillingAddress.PostalCode = supplierOld.BillingAddress.PostalCode;
                    supplier.BillingAddress.Region = supplierOld.BillingAddress.Region;
                    supplier.BillingAddress.StreetName = supplierOld.BillingAddress.StreetName;
                }
                supplier.CompanyName = supplierOld.CompanyName;
                supplier.Contact = supplierOld.Contact;
                supplier.Email = supplierOld.Email;
                supplier.Fax = supplierOld.Fax;
                supplier.SelfBillingIndicator = supplierOld.SelfBillingIndicator;
                if (supplierOld.ShipFromAddress != null)
                {
                    supplier.ShipFromAddress = new SupplierAddressStructure[]
                    {
                        new SupplierAddressStructure
                        {
                            AddressDetail = supplierOld.ShipFromAddress.AddressDetail,
                            BuildingNumber = supplierOld.ShipFromAddress.BuildingNumber,
                            City = supplierOld.ShipFromAddress.City,
                            Country = supplierOld.ShipFromAddress.Country,
                            PostalCode = supplierOld.ShipFromAddress.PostalCode,
                            Region = supplierOld.ShipFromAddress.Region,
                            StreetName = supplierOld.ShipFromAddress.StreetName
                        }
                    };
                }
                supplier.SupplierID = supplierOld.SupplierID;
                supplier.SupplierTaxID = supplierOld.SupplierTaxID;
                supplier.Telephone = supplierOld.Telephone;
                supplier.Website = supplierOld.Website;

                suppliers.Add(supplier);
            }

            return suppliers.ToArray();
        }

        private static TaxTableEntry[] GetTaxTable(IEnumerable<Model.V1.TaxTable> taxesOld)
        {
            if (taxesOld == null)
                return null;

            List<TaxTableEntry> taxes = new List<TaxTableEntry>();

            if (taxesOld.Count() > 0)
            {
                foreach (Model.V1.TaxTableEntry taxOld in taxesOld.FirstOrDefault().TaxTableEntry)
                {
                    TaxTableEntry tax = new TaxTableEntry();
                    tax.Description = taxOld.Description;
                    tax.Item = taxOld.Item;
                    tax.ItemElementName = EnumParser.Parse<ItemChoiceType2>(taxOld.ItemElementName.ToString());
                    tax.TaxCode = taxOld.TaxCode;
                    tax.TaxCountryRegion = taxOld.TaxCountryRegion;
                    tax.TaxExpirationDate = taxOld.TaxExpirationDate;
                    tax.TaxExpirationDateSpecified = taxOld.TaxExpirationDateSpecified;
                    tax.TaxType = EnumParser.Parse<TaxType>(taxOld.TaxType.ToString());

                    taxes.Add(tax);
                }
            }
            return taxes.ToArray();
        }

        private static Product[] GetProducts(IEnumerable<Model.V1.Product> productsOld)
        {
            if (productsOld == null)
                return null;

            List<Product> produtos = new List<Product>();

            foreach (Model.V1.Product productOld in productsOld)
            {
                Product product = new Product();
                product.ProductCode = productOld.ProductCode;
                product.ProductDescription = productOld.ProductDescription;
                product.ProductGroup = productOld.ProductGroup;
                product.ProductNumberCode = productOld.ProductNumberCode;
                product.ProductType = EnumParser.Parse<ProductType>(productOld.ProductType.ToString());

                produtos.Add(product);
            }

            return produtos.ToArray();
        }

        private static Customer[] GetCustomers(IEnumerable<Model.V1.Customer> customersOld)
        {
            if (customersOld == null)
                return null;

            List<Customer> customers = new List<Customer>();

            Customer customer = null;
            foreach (Model.V1.Customer customerOld in customersOld)
            {
                customer = new Customer();
                customer.AccountID = customerOld.AccountID;
                if (customerOld.BillingAddress != null)
                {
                    customer.BillingAddress = new AddressStructure();
                    customer.BillingAddress.AddressDetail = customerOld.BillingAddress.AddressDetail;
                    customer.BillingAddress.BuildingNumber = customerOld.BillingAddress.BuildingNumber;
                    customer.BillingAddress.City = customerOld.BillingAddress.City;
                    customer.BillingAddress.Country = customerOld.BillingAddress.Country;
                    customer.BillingAddress.PostalCode = customerOld.BillingAddress.PostalCode;
                    customer.BillingAddress.Region = customerOld.BillingAddress.Region;
                    customer.BillingAddress.StreetName = customerOld.BillingAddress.StreetName;
                }
                customer.CompanyName = customerOld.CompanyName;
                customer.Contact = customerOld.Contact;
                customer.CustomerID = customerOld.CustomerID;
                customer.CustomerTaxID = customerOld.CustomerTaxID;
                customer.Email = customerOld.Email;
                customer.Fax = customerOld.Fax;
                customer.SelfBillingIndicator = customerOld.SelfBillingIndicator;
                if (customerOld.ShipToAddress != null)
                {
                    customer.ShipToAddress = new AddressStructure[]
                    {
                        new AddressStructure
                        {
                            AddressDetail = customerOld.ShipToAddress.AddressDetail,
                            BuildingNumber = customerOld.ShipToAddress.BuildingNumber,
                            City = customerOld.ShipToAddress.City,
                            Country = customerOld.ShipToAddress.Country,
                            PostalCode = customerOld.ShipToAddress.PostalCode,
                            Region = customerOld.ShipToAddress.Region,
                            StreetName = customerOld.ShipToAddress.StreetName
                        }
                    };
                }
                customer.Telephone = customerOld.Telephone;
                customer.Website = customerOld.Website;

                customers.Add(customer);
            }

            return customers.ToArray();
        }
        #endregion
    }
}
